/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.asom.player.service;

import android.content.ContentResolver;
import android.content.Context;
import android.os.Binder;

/**
 * 
 * @author Ovidiu
 */
public class Player extends Binder
{
	MediaLibrary library;
	
	static Object instance;

	void load(ContentResolver _contentResolver)
    {
		library = new MediaLibrary(_contentResolver);
    }

	Player(ContentResolver _contentResolver)
	{
		if (_contentResolver != null)
			setContentResolver(_contentResolver);
	}
	
	public static Player getInstance(ContentResolver _contentResolver)
	{
		if (instance == null)
			instance = new Player(_contentResolver);
		
		return (Player)instance;
	}
	
	public void setContentResolver(ContentResolver _contentResolver)
	{
		if (library == null)
			this.load(_contentResolver);
	}
	
	public void setContext(Context _context)
	{
		library.setContext(_context);
	}
	
	public void play()
	{
		library.play();
	}
	
	public void play(Song _song)
	{
		if (library.isPlaying())
			library.stop();
		
		library.play(_song);
	}

	public void pause()
	{
		library.pause();
	}

	public boolean isPlaying()
	{
		return library.isPlaying();
	}
	
	public void favorite()
	{
		library.favorite();
	}
	
	public void favorite(Song _song)
	{
		library.favorite(_song);
	}

	public void stop()
	{
		library.stop();
	}

	public void next()
	{
		if (library.isPlaying())
			library.stop();

		library.next();
	}

	public void prev()
	{
		if (library.isPlaying())
			library.stop();

		library.prev();
	}
	
	public void setShuffle(boolean _shuffle)
	{
		library.setShuffle(_shuffle);
	}
	
	public boolean getShuffle()
	{
		return library.getShuffle();
	}
	
	public MediaPlaylist[] getPlaylists()
	{
		return library.getPlaylists();
	}
	
	public Song[] getSongs()
	{
		return library.getSongs();
	}
	
	public Artist[] getArtists()
	{
		return library.getArtists();
	}
	
	public Album[] getAlbums()
	{
		return library.getAlbums();
	}
	
	public Song[] getFavorites()
	{
		return library.getFavorites();
	}
	
	public void save()
	{
		library.save();
	}
}
